package com.example.ysdt.service.impl;

import com.example.ysdt.Vo.ProductLabelVo;
import com.example.ysdt.entiey.Product;
import com.example.ysdt.entiey.ProductLabel;
import com.example.ysdt.service.ProductLabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ProductLabelServiceImpl implements ProductLabelService {
    @Autowired
    private com.example.ysdt.mapper.ProductLabelMapper productLabelMapper;

    @Override
    public List<ProductLabel> queryProductLabel(ProductLabelVo productLabelVo) {
        return productLabelMapper.queryProductLabel(productLabelVo);
    }

    @Override
    public List<ProductLabel> addProductLabel(ProductLabelVo productLabelVo) {
        List<ProductLabel> labels = productLabelVo.getAddProductList().stream()
                .map(product_id -> {
                    ProductLabel label = new ProductLabel();
                    label.setLabel_no(productLabelVo.getLabel_no());
                    label.setProduct_id(product_id);
                    return label;
                })
                .collect(Collectors.toList());
        productLabelMapper.addProductLabel(labels);
        return labels;
    }
}
